/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package clase;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author AJ
 */
public class ListaArchivos {
public static void main (String args[]){
    /*final File f = new File("C:/Documents and Settings/AJ/Mis documentos/Descargas");
    final Frame ff = new Frame();
    Button b = new Button("Click");
    b.addActionListener(new ActionListener(){

        public void actionPerformed(ActionEvent e){
     JFileChooser fd = new JFileChooser(f);

     fd.showOpenDialog(ff);
     fd.showDialog(ff,null);


   System.out.println(fd.getSelectedFile().getAbsolutePath());
    }
    });
    ff.add(b);
    ff.setSize(300,300);
    ff.setResizable(false);
    ff.setVisible(true);*/
    File f = new File("C:/Documents and Settings/AJ/Mis documentos/Descargas");
    String cad = "<lst>";


    for (File a: f.listFiles()){
        if (a.isFile())
        //System.out.println(a.getName());
        cad = cad+","+a.getName();

        }
System.out.println(cad);
List l = new ArrayList();
String arr[]=cad.split(",");
for (int x=1;x<arr.length;x++){
    l.add(arr[x]);
}
cad="<bsc>,JLO";
String arr2 []=cad.split(",");
for (Object s: l){
    String ss= (String)s;
    if (ss.contains(arr2[1]))
        System.out.println("Archivo Encontrado"+ss);
    try{
        FileInputStream fr = new FileInputStream("C:/Documents and Settings/AJ/Mis documentos/Descargas/JLO.JPEG");
        FileOutputStream fw = new FileOutputStream("C:/Documents and Settings/AJ/Mis documentos/Descargas/JLO.JPEG");
        byte bite;
        while ((bite = fr.read())!=-1){
            fw.write(bite);
        }
    fr.close();
    fw.close();

    }catch (Exception e){
        e.printStackTrace();
    }
}



}

}
